home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
ZSI
/
dispatch.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
9KB
|
258 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import types
import os
import sys
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from ZSI import *
from ZSI import _child_elements, _copyright, _seqtypes, _find_arraytype, _find_type, resolvers
from ZSI.auth import _auth_tc, AUTH, ClientBinding
_client_binding = None
def GetClientBinding():
return _client_binding
gettypecode = lambda mod, e: getattr(mod, str(e.localName)).typecode
def _Dispatch(ps, modules, SendResponse, SendFault, nsdict = { }, typesmodule = None, gettypecode = gettypecode, rpc = False, docstyle = False, **kw):
global _client_binding
try:
what = str(ps.body_root.localName)
if modules is None:
modules = (sys.modules['__main__'],)
handlers = _[1]
handlers = _[2]
if len(handlers) > 1:
raise TypeError('Multiple implementations found: ' + `handlers`)
handler = handlers[0]
_client_binding = ClientBinding(ps)
None if docstyle else None<EXCEPTION MATCH>AttributeError
if typesmodule is not None:
kwargs = { }
for e in _child_elements(ps.body_root):
try:
tc = gettypecode(typesmodule, e)
except Exception:
tc = TC.Any()
try:
kwargs[str(e.localName)] = tc.parse(e, ps)
continue
except EvaluateException:
ex = None
SendFault(FaultFromZSIException(ex), **kw)
return None
continue
result = handler(**kwargs)
aslist = False
if type(result) in _seqtypes:
for o in result:
aslist = hasattr(result, 'typecode')
if aslist:
break
continue
None<EXCEPTION MATCH>EvaluateException
elif type(result) is not dict:
aslist = not hasattr(result, 'typecode')
result = (result,)
tc = TC.Any(pname = what + 'Response', aslist = aslist)
else:
tp = _find_type(ps.body_root)
if not type(tp) in (tuple, list) or tp[1] == 'Array':
pass
isarray = _find_arraytype(ps.body_root)
data = _child_elements(ps.body_root)
tc = TC.Any()
if isarray and len(data) == 0:
result = handler()
elif isarray:
try:
arg = [ tc.parse(e, ps) for e in data ]
except EvaluateException:
e = None
SendFault(RuntimeError('THIS IS AN ARRAY: %s' % isarray))
return None
result = handler(*arg)
else:
try:
kwarg = []([ (str(e.localName), tc.parse(e, ps)) for e in data ])
except EvaluateException:
e = None
SendFault(FaultFromZSIException(e), **kw)
return None
result = handler(**kwarg)
tc = TC.Any(pname = what + 'Response')
sw = SoapWriter(nsdict = nsdict)
sw.serialize(result, tc)
return SendResponse(str(sw), **kw)
except Fault:
e = None
return SendFault(e, **kw)
except Exception:
e = None
return SendFault(FaultFromException(e, 0, sys.exc_info()[2]), **kw)
def _ModPythonSendXML(text, code = 200, **kw):
req = kw['request']
req.content_type = 'text/xml'
req.content_length = len(text)
req.send_http_header()
req.write(text)
def _ModPythonSendFault(f, **kw):
_ModPythonSendXML(f.AsSOAP(), 500, **kw)
def _JonPySendFault(f, **kw):
_JonPySendXML(f.AsSOAP(), 500, **kw)
def _JonPySendXML(text, code = 200, **kw):
req = kw['request']
req.set_header('Content-Type', 'text/xml; charset="%s"' % UNICODE_ENCODING)
req.set_header('Content-Length', str(len(text)))
req.write(text)
def _CGISendXML(text, code = 200, **kw):
print 'Status: %d' % code
print 'Content-Type: text/xml; charset="%s"' % UNICODE_ENCODING
print 'Content-Length: %d' % len(text)
print ''
print text
def _CGISendFault(f, **kw):
_CGISendXML(f.AsSOAP(), 500, **kw)
class SOAPRequestHandler(BaseHTTPRequestHandler):
server_version = 'ZSI/1.1 ' + BaseHTTPRequestHandler.server_version
def send_xml(self, text, code = 200):
self.send_response(code)
if text:
self.send_header('Content-type', 'text/xml; charset="%s"' % UNICODE_ENCODING)
self.send_header('Content-Length', str(len(text)))
self.end_headers()
if text:
self.wfile.write(text)
self.wfile.flush()
def send_fault(self, f, code = 500):
self.send_xml(f.AsSOAP(), code)
def do_POST(self):
try:
ct = self.headers['content-type']
if ct.startswith('multipart/'):
cid = resolvers.MIMEResolver(ct, self.rfile)
xml = cid.GetSOAPPart()
ps = ParsedSoap(xml, resolver = cid.Resolve)
else:
length = int(self.headers['content-length'])
ps = ParsedSoap(self.rfile.read(length))
except ParseException:
e = None
self.send_fault(FaultFromZSIException(e))
return None
except Exception:
e = None
self.send_fault(FaultFromException(e, 1, sys.exc_info()[2]))
return None
_Dispatch(ps, self.server.modules, self.send_xml, self.send_fault, docstyle = self.server.docstyle, nsdict = self.server.nsdict, typesmodule = self.server.typesmodule, rpc = self.server.rpc)
def AsServer(port = 80, modules = None, docstyle = False, nsdict = { }, typesmodule = None, rpc = False, addr = ''):
address = (addr, port)
httpd = HTTPServer(address, SOAPRequestHandler)
httpd.modules = modules
httpd.docstyle = docstyle
httpd.nsdict = nsdict
httpd.typesmodule = typesmodule
httpd.rpc = rpc
httpd.serve_forever()
def AsCGI(nsdict = { }, typesmodule = None, rpc = False, modules = None):
if os.environ.get('REQUEST_METHOD') != 'POST':
_CGISendFault(Fault(Fault.Client, 'Must use POST'))
return None
ct = os.environ['CONTENT_TYPE']
try:
if ct.startswith('multipart/'):
cid = resolvers.MIMEResolver(ct, sys.stdin)
xml = cid.GetSOAPPart()
ps = ParsedSoap(xml, resolver = cid.Resolve)
else:
length = int(os.environ['CONTENT_LENGTH'])
ps = ParsedSoap(sys.stdin.read(length))
except ParseException:
e = None
_CGISendFault(FaultFromZSIException(e))
return None
_Dispatch(ps, modules, _CGISendXML, _CGISendFault, nsdict = nsdict, typesmodule = typesmodule, rpc = rpc)
def AsHandler(request = None, modules = None, **kw):
ps = ParsedSoap(request)
kw['request'] = request
_Dispatch(ps, modules, _ModPythonSendXML, _ModPythonSendFault, **kw)
def AsJonPy(request = None, modules = None, **kw):
kw['request'] = request
if request.environ.get('REQUEST_METHOD') != 'POST':
_JonPySendFault(Fault(Fault.Client, 'Must use POST'), **kw)
return None
ct = request.environ['CONTENT_TYPE']
try:
if ct.startswith('multipart/'):
cid = resolvers.MIMEResolver(ct, request.stdin)
xml = cid.GetSOAPPart()
ps = ParsedSoap(xml, resolver = cid.Resolve)
else:
length = int(request.environ['CONTENT_LENGTH'])
ps = ParsedSoap(request.stdin.read(length))
except ParseException:
e = None
_JonPySendFault(FaultFromZSIException(e), **kw)
return None
_Dispatch(ps, modules, _JonPySendXML, _JonPySendFault, **kw)
if __name__ == '__main__':
print _copyright